<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title data-i18n="resources.title_geometryBatchAnalystService"></title>
    <script type="text/javascript" src="../js/include-web.js"></script>
</head>
<body style="margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
<div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
<script type="text/javascript" src="../../dist/leaflet/include-leaflet.js"></script>
<script type="text/javascript">
    var host = window.isLocal ? window.server : "https://iserver.supermap.io";
    var baseUrl = host + "/iserver/services/map-jingjin/rest/maps/京津地区地图",
        serviceUrl = host + "/iserver/services/spatialanalyst-sample/restjsr/spatialanalyst",
        map = L.map('map', {
            crs: L.CRS.EPSG4326,
            center: [40, 117],
            maxZoom: 18,
            zoom: 8
        });
    new L.supermap.TiledMapLayer(baseUrl, {noWrap: true}).addTo(map);

    batchAnalystFromGeometry();

    function batchAnalystFromGeometry() {
        //缓冲区分析数据：
        var bufferLine = {
            "type": "Feature",
            "geometry": {
                "type": "LineString",
                "coordinates": [[117, 40.50], [118, 40]]
            }
        };
        var bufferPoint = {
            "type": "Feature",
            "geometry": {
                "type": "Point",
                "coordinates": [117, 40]
            }
        };
        //叠加分析数据：
        var sourceGeometry = {
            "type": "Feature",
            "geometry": {
                "type": "Polygon",
                "coordinates": [[[116, 39.75],
                    [116, 39.15],
                    [117, 39.15],
                    [117, 39.85],
                    [116, 39.85]]]
            }
        };
        var operateGeometry = {
            "type": "Feature",
            "geometry": {
                "type": "Polygon",
                "coordinates": [[[116.25, 40.5],
                    [116.25, 38.5],
                    [116.75, 38.5],
                    [116.75, 40.5],
                    [116.25, 40.5]]]
            }
        };

        //数据加载到地图：
        var geojsonFeature = {
            "type": "FeatureCollection",
            "features": [bufferLine, bufferPoint, sourceGeometry, operateGeometry]
        };

        L.geoJSON(geojsonFeature, {
            style: function (feature) {
                if (feature.geometry.type === "LineString") {
                    return {
                        "color": "blue",
                        "weight": 1.5,
                    };
                } else if (feature.geometry.type === "Polygon") {
                    return {
                        "weight": 1.5,
                        "color": "blue",
                        "opacity": 0.15
                    };
                }
            }
        }).addTo(map);

        //缓冲区分析参数
        var geoBufferAnalystParams = {
            analystName: "buffer",
            param: new L.supermap.GeometryBufferAnalystParameters({
                sourceGeometry: bufferLine,
                sourceGeometrySRID: 4326,
                bufferSetting: new L.supermap.BufferSetting({
                    endType: L.supermap.BufferEndType.ROUND,
                    leftDistance: new L.supermap.BufferDistance({value: 5000}),
                    rightDistance: new L.supermap.BufferDistance({value: 5000}),
                    semicircleLineSegment: 10
                })

            })
        };
        var geoBufferAnalystParams_Point = {
            analystName: "buffer",
            param: new L.supermap.GeometryBufferAnalystParameters({
                sourceGeometry: bufferPoint,
                sourceGeometrySRID: 4326,
                bufferSetting: new L.supermap.BufferSetting({
                    endType: L.supermap.BufferEndType.ROUND,
                    leftDistance: new L.supermap.BufferDistance({value:5000}),
                    rightDistance: new L.supermap.BufferDistance({value: 5000}),
                    radiusUnit: "METER",
                    semicircleLineSegment: 10
                })

            })
        };

        //叠加分析参数
        var OverlayBatchAnalystParameters = {
            analystName: "overlay",
            param: new L.supermap.GeometryOverlayAnalystParameters({
                sourceGeometry: sourceGeometry,
                operateGeometry: operateGeometry,
                operation: L.supermap.OverlayOperationType.CLIP
            })
        };

        //批量分析参数
        var paramter = [geoBufferAnalystParams, OverlayBatchAnalystParameters, geoBufferAnalystParams_Point];

        //批量分析
        new L.supermap.SpatialAnalystService(serviceUrl).geometrybatchAnalysis(paramter).then(function (serviceResult) {
            //结果展示
            var overlayResultStyle = {
                "color": "red",
                "opacity": 0.65
            };

            var bufferResultLayer = L.geoJSON([serviceResult.result[0].resultGeometry, serviceResult.result[2].resultGeometry], {
                style: overlayResultStyle
            }).addTo(map);
            bufferResultLayer.on("mousemove", function (e) {
                e.layer.bindPopup('<h4>'+resources.text_bufferAnalystResult+'</h4>').openPopup();
            });
            bufferResultLayer.on("mouseout", function (e) {
                e.layer.closePopup();
            });

            var overlayResultLayer = L.geoJSON(serviceResult.result[1].resultGeometry, {
                style: overlayResultStyle
            }).addTo(map);
            overlayResultLayer.on("mousemove", function (e) {
                e.layer.bindPopup('<h4>'+resources.text_overlayAnalystResult+'</h4>').openPopup();
            });
            overlayResultLayer.on("mouseout", function (e) {
                e.layer.closePopup();
            });
        });
    }
</script>
</body>
</html>